package calendar;

import java.util.ArrayList;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import common.PagingVo;

public class CalendarList {

	CalendarMyba dao;
	
	public void setDao(CalendarMyba dao) {
		this.dao = dao;
	}
	
	@RequestMapping("/CalList.cal")
	public ModelAndView insertForm(CalendarVo cv, @RequestParam(value="ajaxFlag") String ajaxFlag){
		ModelAndView mav = new ModelAndView();
		dao.setCv(cv);
		//페이징
		int tot = dao.totalRow();
		int nowPage = 1;
		if(cv.getCalNowPage() > 0) nowPage = cv.getCalNowPage();
		//검색 버튼으로 들어왔을시
		if(ajaxFlag.equals("1")){
			cv.setCalNowPage(1);
			nowPage = 1;
		}
		PagingVo paging = new PagingVo();
		paging.setListSize(5);
		paging = paging.computer(tot, nowPage);
		mav.addObject("paging", paging);
		cv.setStartNo(paging.getStartNo());
		cv.setEndNo(paging.getEndNo());
		dao.setCv(cv);
		ArrayList<CalendarVo> lists = dao.select();
		mav.addObject("lists", lists);
		mav.addObject("cv",cv);
		mav.setViewName("/homepage/calSpring/calendar_list_view.jsp");
		return mav;
	}
	
}
